package cn.itcast.bos.mq;

import java.io.UnsupportedEncodingException;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Service;

import cn.itcast.bos.util.SmsUtils;

@Service("smsConsumer")
public class SmsConsumer implements MessageListener {

	@Override
	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage) message;
		String result;
		try {
			result = SmsUtils.sendSmsByHTTP(mapMessage.getString("telephone"), mapMessage.getString("msg"));
			result ="000/xxxx";
			if (result.startsWith("000")){
				//发送成功
				System.out.println(mapMessage.getString("telephone")+"active为:"+mapMessage.getString("msg"));
				
			} else {
				
				
				throw new RuntimeException("发送短信失败,信息码:" + result);
			}
		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
}
